﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/7/2009
 * Time: 6:46 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using NUnit.Framework;
using Buaya.Model;

namespace Buaya.Tests
{
	[TestFixture]
	public class UserTests
	{
		[Test]
		public void TestMethod()
		{
			User u = SessionFacade.ReadUserByNameAndPassword("admin", "root");
			if (u == null) {
				Console.WriteLine("User not found!");
				return;
			}
			Module m = SessionFacade.ReadModuleByPk(15);
			foreach (ModuleCommand c in m.Commands) {
				Console.WriteLine(c.Name);
			}
			UserModule um = new UserModule(m);
			um.AddCommand(new UserModuleCommand(m.Commands[0]));
			um.AddCommand(new UserModuleCommand(m.Commands[2]));
			u.AddModule(um);
			SessionFacade.SaveOrUpdateUser(u);
		}
		
		[Test]
		public void TestMethod2()
		{
			User u = SessionFacade.ReadUserByNameAndPassword("admin", "root");
			Console.WriteLine("User: " + u.Name);
			Console.WriteLine("Listing " + u.Modules.Count + " modules...");
			foreach (UserModule m in u.Modules) {
				Console.WriteLine("Module: " + m.Module.Name);
				Console.WriteLine("Listing Commands...");
				foreach (UserModuleCommand s in m.Commands) {
					Console.WriteLine(s.ModuleCommand.Name);
				}
			}
		}
	}
}
